import base from './base';
import * as Common from './common';
import { doSubmitForm } from './submit';
import { reloadRequestPage } from './formUtil'
import * as API_REQ from '../apis/form';
import { Bubble } from 'weaver-mobile';
const getLabel = Common.getLabel;


//显示连续处理自动切换的提示
export const showConProcessSwitchTip = (queryParams) => {
    if(queryParams.showConProcessSwitchTip == '1') {
        Bubble.success(getLabel(528806, '流程已处理，自动为您打开下一条'), 3);
    }
}

//连续处理切换流程
export const switchRequest = (type, closeFunc, showConProcessSwitchTip) => {
    const {continuationProcessInfo} = base.wfGlobalStore;
    const {currentIndex, requestId} = continuationProcessInfo;

    let switchToRequestId = '';
    
    //获取跳转的下一requestid
    let searchConditionParams = localStorage.continuationProcess_searchConditionParams ? JSON.parse(localStorage.continuationProcess_searchConditionParams) : {};
    API_REQ.getContinnuationProcessInfo({
        viewScope: "doing",
        switchType : type,
        currentIndex : currentIndex,
        currentRequestId : requestId,
        ...searchConditionParams
    }).then(data => {
        if (data.switchRequestId > 0) {
            switchToRequestId = data.switchRequestId;
            reloadRequestPage({requestid: switchToRequestId, isOpenContinuationProcess  : '1', f_weaver_belongto_userid : data.userId,f_weaver_belongto_usertype : data.userType, showConProcessSwitchTip : (showConProcessSwitchTip ? '1' : '0') });
        } else  {
            closeFunc && closeFunc();
            try {
                window.top.close();
            } catch (e) {
                window.close();
            }
        }
    })

  }
